import { cline, obj_str, uDb, loc, add_ck_col, reload_col, ck_sn, ck_empty } from 'sui';

const get_fix = () => {
    return [
        {sn: "sn", name: loc("l_495"), tp: "string"},
        {sn: "name", name: loc("l_189"), tp: "string"},
    ];
};

const get_ck = (cur, main, col) => {
    const ret = {
        sn : v => ck_sn(v, cur, main),
        name : v => ck_empty(v),
    };

    add_ck_col(ret, col);

    return ret;
};

const load_col = (setCol) => {
    const fix = get_fix();
    reload_col(null, v => setCol(v), "kind", fix);
};

const load_item = (hDone, cur, setUser) => {
    uDb(hDone, "file/get/gkind",
        {
            line: cline(),
            sn: obj_str(cur, "sn"),
        },
        r => setUser(r["user"]), e => setUser(null));
};

export {load_item, load_col, get_ck, get_fix};
